package com.haipumi.servlets.backadmin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.haipumi.beans.DataGrid;
import com.haipumi.beans.haipumi_activity;
import com.haipumi.biz.IBackActivityBiz;
import com.haipumi.biz.impl.BackActivityBizImpl;
import com.haipumi.servlets.CommonServlet;
import com.haipumi.utils.RequestUtil;

public class BackActivesServlet extends CommonServlet {

	IBackActivityBiz ibab=new BackActivityBizImpl();
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//先从request里获取op选项为多少
		String op=request.getParameter("op");
		if("findallactivity".equals(op)){
			findallactivity(request,response);
		}else if("addactivity".equals(op)){
			addactivity(request,response);
		}else if("updateactivity".equals(op)){
			updateactivity(request,response);
		}
	}

	private void updateactivity(HttpServletRequest request,
			HttpServletResponse response) {
		haipumi_activity activity=RequestUtil.parseRequest(request, haipumi_activity.class);
		haipumi_activity backactivity=null;
		backactivity=ibab.editActivity(activity);
		super.outData(response, backactivity);
	}

	private void addactivity(HttpServletRequest request,
			HttpServletResponse response) {
		haipumi_activity activity=RequestUtil.parseRequest(request, haipumi_activity.class);
		haipumi_activity backactivity=null;
		backactivity=ibab.addActivity(activity);
		super.outData(response, backactivity);
		
	}

	private void findallactivity(HttpServletRequest request,
			HttpServletResponse response) {
		List<haipumi_activity>activitylist=null;
		activitylist=ibab.findAllActivity();
		int r=0;
		r=ibab.countAllActivity();
		DataGrid dg=new DataGrid();
		dg.setRows(activitylist);
		dg.setTotal(r);
		super.outData(response, dg);
	}

}
